package com.ruoyi.media.publishModelConfig.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.media.publishModelConfig.domain.vo.MediaPublishModelConfigVo;
import com.ruoyi.media.publishModelConfig.domain.bo.MediaPublishModelConfigBo;
import com.ruoyi.media.publishModelConfig.service.IMediaPublishModelConfigService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发布模板配置
 *
 * @author dqw
 * @date 2023-03-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/publishModelConfig/publishModelConfig")
public class MediaPublishModelConfigController extends BaseController {

    private final IMediaPublishModelConfigService iMediaPublishModelConfigService;

    /**
     * 查询发布模板配置列表
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:list")
    @GetMapping("/list")
    public TableDataInfo<MediaPublishModelConfigVo> list(MediaPublishModelConfigBo bo, PageQuery pageQuery) {
        return iMediaPublishModelConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出发布模板配置列表
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:export")
    @Log(title = "发布模板配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MediaPublishModelConfigBo bo, HttpServletResponse response) {
        List<MediaPublishModelConfigVo> list = iMediaPublishModelConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "发布模板配置", MediaPublishModelConfigVo.class, response);
    }

    /**
     * 获取发布模板配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:query")
    @GetMapping("/{id}")
    public R<MediaPublishModelConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMediaPublishModelConfigService.queryById(id));
    }

    /**
     * 新增发布模板配置
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:add")
    @Log(title = "发布模板配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MediaPublishModelConfigBo bo) {
        return toAjax(iMediaPublishModelConfigService.insertByBo(bo));
    }

    /**
     * 修改发布模板配置
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:edit")
//    @Log(title = "发布模板配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MediaPublishModelConfigBo bo) {
        return toAjax(iMediaPublishModelConfigService.updateByBo(bo));
    }

    /**
     * 删除发布模板配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("publishModelConfig:publishModelConfig:remove")
    @Log(title = "发布模板配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMediaPublishModelConfigService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
